﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using WPFDemoMVVM.Controls;
using WPFDemoMVVM.View;

namespace WPFDemoMVVM.ViewModel
{
    public partial class ParentWindowViewModel : ObservableObject
    {
        private readonly MetroWindow _mainWindow;
        public ParentWindowViewModel(MetroWindow mainWindow)
        {
            _mainWindow = mainWindow;

            MenuItems = new ObservableCollection<HamburgerMenuItem>
            {
                //new HamburgerMenuItem { Label = "首页", Icon = "Home", Page = new Views.HomePage() },
                //new HamburgerMenuItem { Label = "设置", Icon = "Cogs", Page = new Views.SettingsPage() },
                //new HamburgerMenuItem { Label = "报表", Icon = "ChartBar", Page = new Views.ReportPage() }

                new HamburgerMenuItem { Label = "首页", Icon = "Home", Page = new HomePage() },
                new HamburgerMenuItem { Label = "设置", Icon = "Cogs", Page = new SettingsPage() },
                new HamburgerMenuItem { Label = "报表", Icon = "ChartBar", Page = new ReportPage() }

            };
            CurrentPage = MenuItems.First().Page;

            MenuItemInvokedCommand = new RelayCommand<object>(OnMenuItemInvoked);
        }

        [RelayCommand]
        private void OpenChild()
        {
            var childWindow = new ChildView
            {
                Owner = _mainWindow
            };
            childWindow.ShowDialog(); // 或 Show() 非模态
        }

        [RelayCommand]
        private async Task ShowConfirm()
        {
            //var settings = new MetroDialogSettings
            //{
            //    AffirmativeButtonText = "确定",
            //    NegativeButtonText = "取消",
            //    AnimateShow = true,
            //    AnimateHide = true
            //};


            var settings = new MetroDialogSettings
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText = "No",
                ColorScheme = MetroDialogColorScheme.Accented
            };


            var result = await _mainWindow.ShowMessageAsync("确认操作", "你确定要继续执行吗？",
                            MessageDialogStyle.AffirmativeAndNegative, settings);

            if (result == MessageDialogResult.Affirmative)
            {
                await _mainWindow.ShowMessageAsync("提示", "你点击了“确定”");
            }
            else
            {
                await _mainWindow.ShowMessageAsync("提示", "你点击了“取消”");
            }


            var controller = await _mainWindow.ShowProgressAsync("请稍候", "处理中...");
            controller.SetIndeterminate();
            await Task.Delay(3000);
            await controller.CloseAsync();


        }

        public ObservableCollection<HamburgerMenuItem> MenuItems { get; }

        [ObservableProperty]
        private UserControl currentPage;


        [RelayCommand]
        private void Navigate(object selectedItem)
        {
            if (selectedItem is HamburgerMenuItem menuItem)
            {
                CurrentPage = menuItem.Page;
            }
        }

        public ICommand MenuItemInvokedCommand { get; }
        private void OnMenuItemInvoked(object obj)
        {
            // obj 就是你点击的 HamburgerMenuItem
            var item = obj as HamburgerMenuItem;
            Debug.WriteLine($"点击了：{item?.Label}");
        }
    }


    public class HamburgerMenuItem
    {
        public string Label { get; set; }
        public string Icon { get; set; } // 如 FontAwesome 图标名
        public UserControl Page { get; set; }
    }
}
